package com.cvte.boe.media.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;

import com.cvte.boe.media.R;
import com.cvte.boe.media.model.LocalMediaInfo;
import com.cvte.boe.media.views.widget.MarqueeTextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wuguitong on 2018/5/17.
 */
public class AudioFileAdapter extends BaseAdapter{
    private Context mContext;
    private List<LocalMediaInfo> mMediaInfoList;
    private int curFileIndex;
    private boolean bIsPause;
    public AudioFileAdapter(Context context, List<LocalMediaInfo> list){
        this.mContext = context;
        mMediaInfoList = new ArrayList<>();
        mMediaInfoList.clear();
        mMediaInfoList.addAll(list);
        curFileIndex = 0;
        bIsPause = false;
    }
    @Override
    public int getCount() {
        return mMediaInfoList.size();
    }

    @Override
    public Object getItem(int i) {
        return mMediaInfoList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        AudioViewHolder holder = null;
        LocalMediaInfo info = mMediaInfoList.get(position);
        if(convertView == null){
            holder = new AudioViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_audio_file_status,null);
            holder.tvNmae = (MarqueeTextView)convertView.findViewById(R.id.tv_audio_file_name);
            holder.tvPath = (MarqueeTextView)convertView.findViewById(R.id.tv_audio_file_path);
            holder.ivStatus = (ImageView)convertView.findViewById(R.id.iv_audio_file_status);
            convertView.setTag(holder);
        }else{
            holder = (AudioViewHolder)convertView.getTag();
        }
        holder.tvNmae.setText(info.getFileName());
        holder.tvPath.setText(info.getFileAllName());
        int resId = R.drawable.audio_file_status_normal;
        if(curFileIndex == position){
            if(bIsPause){
                resId = R.drawable.audio_file_status_pause;
            }else{
                resId = R.drawable.audio_file_status_play;
            }
        }
        holder.ivStatus.setImageResource(resId);
        return convertView;
    }
    class AudioViewHolder {
        MarqueeTextView tvNmae;
        MarqueeTextView tvPath;
        ImageView ivStatus;
    }
    public void setCurAudioFileStatus(int index,boolean isPause){
        this.curFileIndex = index;
        this.bIsPause = isPause;
    }
}
